package com.lening.controller;

import com.lening.entity.OrderBean;
import com.lening.entity.PowerBean;
import com.lening.entity.ProductBean;
import com.lening.entity.UserBean;
import com.lening.service.StuService;
import com.lening.utils.Page;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class StuController {
    @Resource
    StuService stuService;
    @RequestMapping("/getPowerJson")
    public ModelAndView getPowerJson(){
        ModelAndView mv = new ModelAndView("left");
        List<PowerBean> list = stuService.getPowerList();
        String json = JSONArray.fromObject(list).toString();
        mv.addObject("json", json);
        String aa = "contt";
        return mv;

    }
    @RequestMapping("/getUserList")
    public ModelAndView getUserList(Page page, String yema){
        ModelAndView mv = new ModelAndView("user_list");
        int count=stuService.getUserCount();
        page=new Page(yema,count,"4");
        List<UserBean> list = stuService.getUserList(page);
        mv.addObject("list",list);
        mv.addObject("page",page);
        return mv;
    }
    @RequestMapping("/getUserOrderList")
    public ModelAndView getUserOrderList(HttpServletRequest request,UserBean ub){
        ModelAndView mv=new ModelAndView("order_list");
        List<OrderBean> olist=stuService.getUserOrderList(ub);
        mv.addObject("olist",olist );
        return mv;
    }
    @RequestMapping("/toBuyPro")
    public ModelAndView toBuyPro(ProductBean pb){
        ModelAndView mv=new ModelAndView("xzsp");
        ProductBean p=stuService.getProById(pb);
        mv.addObject("pb", p);
        return mv;
    }

    @RequestMapping("/getProList")
    public ModelAndView getProList(){
        ModelAndView mv=new ModelAndView("pro_list");
        List<ProductBean> plist=stuService.getProList();
        mv.addObject("plist",plist);
        return mv;
    }


}
